home *** CD-ROM | disk | FTP | other *** search
- Path: news.netkonect.net!usenet
- From: Cliff Davies <cliff@witsend.netkonect.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: #include "" for large programs.
- Date: Sun, 14 Apr 1996 09:53:30 -0700
- Organization: .netkonect (customer account)
- Message-ID: <31712D8A.A25@witsend.netkonect.co.uk>
- References: <Pine.SUN.3.92.960411195730.24973A-100000@suntan>
- NNTP-Posting-Host: witsend.netkonect.co.uk
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (Win16; I)
-
- Carlos Diaz (CS) wrote:
- >
- > Hello!
- > I've been writing short two part programs using the #include "filename"
- > preprocessor.
- > I call one file main.c and the other part2.c, for which there is a
- > prototype header file part2.h.
- > All works well when I compile the programs, except when part2.h has
- > #define constants (I've been advised by my professor to use #define for
- > constants over 'const type var_name'). My compiler returns a fatal error
- > reporting that the symbol in the #define is not defined.
- > For example if #define EQUAL 0 is part of part2.h, I'm told that the
- > symbol EQUAL is not defined. But if I put the #define inside main.c, I'm
- > told that I've defined EQUAL TWICE, once in part2.h and again within
- > main. The book we're using in class is not helping at all in this subject,
- > and I cannot figure out why everything else is recognized, except #define
- > constants. Can anyone here help? If the answer to this is in the FAQ, just
- > tell me where to download it from. Thanks!
- >
- > -Carlos E. Diaz
-
- Just a possibility here - If the defined constant is used in both main.c
- and part2.c, you need to include the header in both files.
- It is also quite useful to include something like the following in header
- files around defines and typedefs -
-
- #ifndef __PART2
- #define __PART2
-
- #define EQUAL 0
- typedef char BOOLEAN
- etc...
-
- #endif
-
- Hope this helps you out.
-